package com.cgt.gym.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cgt.gym.pojo.Admin;
import com.cgt.gym.mapper.AdminMapper;
import com.cgt.gym.pojo.query.AdminQuery;
import com.cgt.gym.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cgt.gym.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {
	@Autowired
	private AdminMapper adminMapper;

	@Override
	public IPage<Admin> list(AdminQuery adminQuery) {
		IPage<Admin> page = new Page<>(adminQuery.getPage(),adminQuery.getLimit());

		QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
		queryWrapper.like(!ObjectUtils.isEmpty(adminQuery.getName()),"name",adminQuery.getName());
		queryWrapper.like(!ObjectUtils.isEmpty(adminQuery.getPhone()),"phone",adminQuery.getPhone());
		queryWrapper.between(!ObjectUtils.isEmpty(adminQuery.getBeginUpdateTime()) && !ObjectUtils.isEmpty(adminQuery.getEndUpdateTime()),
				"update_time", adminQuery.getBeginUpdateTime(), adminQuery.getEndUpdateTime());
		adminMapper.selectPage(page,queryWrapper);
		return page;
	}
}
